package ru.papergames.controller.commands
{
	import flash.ui.Keyboard;
	
	import org.puremvc.as3.interfaces.INotification;
	
	import ru.papergames.controller.commands.BaseCommand;
	import ru.papergames.model.proxies.MessagingSocketProxy;
	import ru.papergames.utils.helpers.KeyboardHelper;

	public class ChatCommand extends BaseCommand
	{
		override public function execute(notification:INotification):void {
			super.execute(notification);
			
			var message:String = notification.getBody() as String;
			var channel:String = notification.getType();
			
			var parts:Array = [];
			var privateTo:String = null;
			
			
			parts = message.split(':');
			privateTo = parts.shift();
			
			if (privateTo && privateTo.search('Приват для ') == 0) {
				privateTo = privateTo.replace('Приват для ', '');
				message = parts.join(':');
			} else {
				privateTo = null;
			}
			
			var recipientId:int = 0;	
			
			if ( !privateTo && !recipientId && 
					KeyboardHelper.checkState(Keyboard.CONTROL) && 
						messagingProxy.battleChannel) {
				
				recipientId = -1;
				
			}
			
			messagingProxy.sendMessage(message, recipientId, false, channel == 'generic');			
			
		}		
		
		
	}
}